<%--
  Created by IntelliJ IDEA.
  User: ljl
  Date: 2024/12/19
  Time: 下午1:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>File Upload to MinIO</title>
</head>
<body>
<h1>Upload Image to MinIO</h1>
<form id="uploadForm" enctype="multipart/form-data">
    <input type="file" id="imgfile" name="imgfile" accept="image/*">
    <button type="button" onclick="uploadFile()">Upload Image</button>
</form>

<h1>Upload File to MinIO</h1>
<form id="uploadFormJL" enctype="multipart/form-data">
    <input type="file" id="jlfile" name="jlfile">
    <button type="button" onclick="uploadFileJL()">Upload File</button>
</form>

<script>
    function uploadFile() {
        var formData = new FormData(document.getElementById('uploadForm'));
        uploadToMinIO('uploadImg1', formData);
    }

    function uploadFileJL() {
        var formData = new FormData(document.getElementById('uploadFormJL'));
        uploadToMinIO('uploadjl1', formData);
    }

    function uploadToMinIO(url, formData) {
        fetch(url, {
            method: 'POST',
            body: formData,
        })
            .then(response => response.text())
            .then(result => {
                console.log('Upload result:', result);
                alert('File uploaded successfully: ' + result);
            })
            .catch(error => {
                console.error('Error:', error);
                alert('Error uploading file');
            });
    }
</script>
</body>
</html>